
{extend name="User/index" /}
{block name="users"}
<style>

</style>
<div class="col-xs-12" style="margin-top: 20px;">
    {if empty($list)}
    <center>
        <div class="col-xs-12" style="margin-top: 40px;">
            <a href="{:url('mobile/Index/index')}">还没有收藏呦！GO->精彩小片</a>
        </div>
    </center>

    {elseif !empty($list)}

    {foreach $list as $v}

    <div class="nav-movie col-xs-4" style="margin-bottom: 10px;">
        <a href="{:url('mobile/Index/show', ['id'=>$v['id']])}">
            <img src="../../../../../uploads/{$v.cover}" alt="" height="120">
            <p class="col-xs-12" style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">{$v.mname}</p>
            <span class="col-xs-12">{$v.score}分</span>
        </a>
        <button class="btn btn-success btn del-fav" data-id="{$v.id}">取消收藏</button>
    </div>
    {/foreach}
    {/if}
</div>

{js href="/static/admin/js/jquery.min.js"}
                    {js href="/static/admin/js/bootstrap.min.js"}
                    <script>
                        $(function(){

                            // 触发取消收藏
                            $('.del-fav').click(function (){
                                var mv_id = $(this).attr('data-id');
                                var obj = $(this).parent();
                                var num = $('#fav-num');
                                favAjax(mv_id, obj, num);
                            });



                            // AJAX取消
                            function favAjax(id,obj,num){
                                $.ajax({
                                    type: 'post',
                                    url: '/mobile/Index/delfav',
                                    data: {
                                        id:id
                                    },
                                    dataType: 'json',
                                    success: function (data) {
                                       if (data.status) {
                                                obj.remove();
                                                num.text(num.text()-1);
                                            } else {
                                             }
                                    },
                                    error: function () {
                                        alert('AJAX操作失败');
                                    }
                                });
                            }

                        })
                    </script>
{/block}

